﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Gameplay.Liberty;
using Yoozoo.Gameplay.Liberty.Nodes;
using Yoozoo.UI.YEvents;
using Yoozoo.UI.YGUI;

public class SkipBtn : MonoBehaviour
{
    [Tooltip("需要跳过的Timeline名称")]
    public string timelineName;
    [Tooltip("是否为Timeline时间跳跃方式")] 
    public bool isJump;
    [Tooltip("点击后跳跃到指定的时间点")] 
    public double jumpTo;
    
    [Tooltip("点击跳过后抛出的蓝图事件名称")] 
    public string[] eventNames;
    [Tooltip("点击跳过后抛出的事件名称")] 
    public string[] eventFunc;
    [Tooltip("用于打点的ID值")] 
    public int reportId;

    
    public void OnSkipClick()
    {
        //点击后先抛出事件
        if (eventFunc.Length > 0)
        {
            foreach (string evtName in eventFunc)
            {
                BlueprintUtils.ExeEventFunc(evtName);
            }
        }
        
        //点击后先抛出事件
        if (eventNames.Length > 0)
        {
            foreach (string evtName in eventFunc)
            {
                BlueprintUtils.SendGraphEvent(evtName, null);
            }
        }
        
        //执行对应的跳过方法
        if (!string.IsNullOrEmpty(timelineName))
        {
            if (isJump)
            {
                PlayTimeline.JumpTimeline?.Invoke(timelineName,jumpTo);
                BlueprintUtils.TimeLineJumpToTime(timelineName , jumpTo);
            }
            else
            {
                PlayTimeline.SkipTimeline?.Invoke(timelineName);
                StartCoroutine(Skip());
            }
        }

        //进行打点
        if (reportId > 0)
        {
            BlueprintUtils.ClientReport(reportId);
        }
    }

    IEnumerator Skip()
    {
        yield return null;
        yield return null;
        yield return null;
        //关闭Timeline
        BlueprintUtils.StopTimeline(timelineName);
    }
}
